package main

import (
	"fmt"
	"time"

	"gitee.com/wuzp__dev/crawler/retriever/mock"
	"gitee.com/wuzp__dev/crawler/retriever/real"
)

type Retriever interface {
	Get(string) string
}

type Poster interface {
	Post(string, map[string]string) string
}

func download(r Retriever) string {
	return r.Get("https://www.imooc.com")
}

func post(poster Poster) {
	poster.Post("https://www.imooc.com",
		map[string]string{
			"name":   "ccmouse",
			"course": "golang",
		})
}

type RetrieverPoster interface {
	Retriever
	Poster
}

func session(s RetrieverPoster) {

}

func main() {
	var r Retriever
	r = mock.Retriever{"this is a fake imooc.com"}
	inspect(r)

	r = &real.Retriever{
		UserAgent: "Mozilla/5.0",
		Timeout:   time.Minute,
	}
	inspect(r)

	if realRetriever, ok := r.(*real.Retriever); ok {
		fmt.Println(realRetriever.Timeout)
	} else {
		fmt.Println("not a real retriever")
	}

	// fmt.Println(download(r))
}

func inspect(r Retriever) {
	fmt.Printf("%T %v\n", r, r)
	fmt.Println("Type switch:")
	switch v := r.(type) {
	case mock.Retriever:
		fmt.Println("Contents:", v.Contents)
	case *real.Retriever:
		fmt.Println("UserAgent:", v.UserAgent)
	}
}
